package com.hotel.controller;


import java.io.UnsupportedEncodingException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hotel.entity.HotelInfo;
import com.hotel.service.HotelService;





//处理酒店模块的查询酒店、扫描二维码、酒店推荐

@Controller
@RequestMapping("/hotel_info")
public class HotelInfoController {
	
	@Resource  
    private HotelService hotelService; 
	
	@ResponseBody
	@RequestMapping(value="/select/{id}", method=RequestMethod.GET)  
    public HotelInfo hotelSelectById(@PathVariable("id") int id){  
		HotelInfo hotelInfo = hotelService.hotelSelectById(id);
		String room_device_ids = hotelInfo.getRoomDeviceIds();
		String hotel_device_ids = hotelInfo.getHotelDeviceIds();
		//把room_device_ids和hotel_device_ids反序列化为数组
		return hotelInfo;
    }  
	
	@ResponseBody
	@RequestMapping(value="/select/{name}", method=RequestMethod.GET)  
    public List<HotelInfo> hotelSelectToGet(@PathVariable("name") String name) throws UnsupportedEncodingException{  
		System.out.println(name);
		String name_utf = new String(name.getBytes("iso-8859-1"),"utf-8");
		List<HotelInfo> list = hotelService.hotelSelect(name_utf);
		return list;
    }  
    
	@ResponseBody
    @RequestMapping(value="/select", method=RequestMethod.POST)  
    public List<HotelInfo> hotelSelectToPost(@RequestBody String name){
		
		List<HotelInfo> list = hotelService.hotelSelect(name);
		return list;
    }  
    
	@ResponseBody
    @RequestMapping(value="/scan/{id}", method=RequestMethod.GET)  
    public HotelInfo hotelScanToGet(@PathVariable("id") int id){
		HotelInfo hotelInfo = hotelService.hotelSelectById(id);
		return hotelInfo;
    }  
    
	@ResponseBody
    @RequestMapping(value="/recommend", method=RequestMethod.GET)  
    public List<HotelInfo> hotelRecommendToGet(){
		List<HotelInfo> list = hotelService.hotelRecommend();
    	return list;
    }  
    
	@ResponseBody
    @RequestMapping(value="/recommend", method=RequestMethod.POST)  
    public List<HotelInfo> hotelRecommendToPost(){
		List<HotelInfo> list = hotelService.hotelRecommend();
    	return list;
    } 
}

